package com.xumingxun.database_sync;

import com.xumingxun.database_sync.domain.Config;
import com.xumingxun.database_sync.domain.Task;
import com.xumingxun.database_sync.sync.impl.DatabaseSync;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;

import javax.annotation.Resource;

@SpringBootApplication
public class DatabaseSyncStarter implements ApplicationRunner {
    public static void main(String[] args) {
        new SpringApplicationBuilder().sources(DatabaseSyncStarter.class).web(WebApplicationType.NONE).run(args);
    }

    @Resource
    DatabaseSync databaseSync;


    @Resource
    Config config;

    @Override
    public void run(ApplicationArguments args) {
        for (Task task : config.getTasks()) {
            switch (task.getType()){
                case database:
                    databaseSync.run(task.getSource(),task.getTarget(),config);
                    break;
            }
        }
    }
}
